home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11315 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  52 lines

  1. Path: news.netins.net!trg1
  2. From: hhowe@trgnet.com (Harold Howe)
  3. Newsgroups: comp.lang.c++
  4. Subject: Efficiency question: private data
  5. Date: Wed, 13 Mar 96 21:19:36 GMT
  6. Organization: Technology Resource Group
  7. Message-ID: <4i7hfc$8na@insosf1.netins.net>
  8. NNTP-Posting-Host: desm-21-21.dialup.netins.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #3
  10.  
  11. Greetings. 
  12.  
  13. I would like to know what is more efficient: passing data to a member 
  14. function, or storing the data and calling the function with no arguments?  For 
  15. example, take the printValue function below.
  16.  
  17. class SomeClass
  18.   {
  19.   public:
  20.     void printValue(void)            { cout << privatevalue;}
  21.     void printValue(int passvalue)   { cout << passvalue;}
  22.   private:
  23.     int privatevalue;
  24.   public: 
  25.     void setPrivateValue(int value)  {privatevalue=value}
  26.   };
  27.  
  28. int main(void)
  29.   {
  30.   SomeClass A;
  31.   A.setPrivateValue(5);
  32.  
  33.   A.printValue();
  34.   A.printValue(6);
  35.   return 0;
  36.   }
  37.  
  38. Which is more efficient, and which is better (if their are OO reasons or 
  39. something).  I have a more realistic situation in which a class's public 
  40. member function is called with a integer ID argument, then this function 
  41. decides to call a private function which needs to know the integer ID.  Should 
  42. I store the ID as a member and call the function with void, or should I call 
  43. the private function with the integer ID as an argument. 
  44.  
  45. All comments are welcome.  If you think one method is better for whatever 
  46. reason, please let me know.
  47.  
  48. Harold Howe
  49. hhowe@trgnet.com 
  50.   
  51.     
  52.